home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-04 | 2.8 KB | 94 lines | [TEXT/MPS ] |
- #
- # File: RandomSample.vu
- #
- # Contains: Example code to help describe the new random number
- # seeding feature.
- #
- # Written by: Chad Williams
- #
- # Copyright: © 1992 by Apple Computer, Inc., all rights reserved.
- #
- # Change History (most recent first):
- #
- # 9/3/92 CMW Created
- #
-
- (************************************************************************************
- * Script RandomSample( seed )
- * This script will make a number of calls to the random number generator, including
- * getting and setting the seed values. If a User provides a value for the 'seed'
- * parameter to the script, the random number generator will be seeded with that
- * value.
- * Note that the seed can be set without changing the script itself!
- ************************************************************************************)
- Script RandomSample( seed )
- begin
-
- println;
-
- # Check to see if the User provided a starting seed.
- if( isundefined(seed) )
- begin
- # No seed provided, so print out the given one.
- # When RandomSeed() is called with no parameters, the random
- # number generator is left untouched.
- # RandomSeed() ALWAYS returns the value of the last seed it had
- # (in this case, the default seed).
- x := RandomSeed();
- println "Default Initial Seed: ", x;
- end;
- else
- begin
- # The User provided a seed.
- # Use it, and log the value used.
- RandomSeed( seed );
- x := RandomSeed();
-
- # Note that 'x' should be equal to 'seed'.
- println "Random Seed initialized by User to: ", x;
- end;
-
- println;
- println "# Random number tests:";
-
- println;
- println "Random( 0, 10 ): ", Random( 0, 10 );
-
- # Note that negative numbers are now legal for the Random range.
- println "Random( -10, 10 ): ", Random( -10, 10 );
- println "Random( -10, 10 ): ", Random( -10, 10 );
- println "Random( -10, 10 ): ", Random( -10, 10 );
- println;
-
-
- # The "Old Seed" will be equal to 'x', the original seed for the
- # random number generator.
- println "Old Seed: ", RandomSeed( 12 );
-
- # The "New Seed" will be equal to 12, the last number the
- # random number generator was seeded with.
- println "New Seed: ", RandomSeed();
- println;
- println "Random( 0, 10 ): ", Random( 0, 10 );
- println "Random( -10, 10 ): ", Random( -10, 10 );
- println "Random( -10, 10 ): ", Random( -10, 10 );
- println "Random( -10, 10 ): ", Random( -10, 10 );
- println;
-
-
- # Now we will reseed the random number generator with the
- # initial seed so to demonstrate that the sequence of numbers
- # given by the random number generator depends only on the
- # seed.
- #
- # This sequence should exactly match the first sequence we printed:
- println "Old Seed: ", RandomSeed( x );
- println "New Seed: ", RandomSeed();
- println;
- println "Random( 0, 10 ): ", Random( 0, 10 );
- println "Random( -10, 10 ): ", Random( -10, 10 );
- println "Random( -10, 10 ): ", Random( -10, 10 );
- println "Random( -10, 10 ): ", Random( -10, 10 );
-
-
- end;